import apiUrl from "./dev.js";

export const formatURL = function (url) {
	if (url) {
		var reg =
			/^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:\/~+#]*[\w\-@?^=%&\/~+#])?$/;
		url = url.replace(/(^\s*)|(\s*$)/g, "");
		if (!reg.test(url)) {
			url = apiUrl.JAVA_SERVE + url;
			return url;
		}
	} else {
		return null;
	}
};

export const setBrowseNumber = function () {
	let Obj = localStorage.getItem("browseNumber");
	let browseNumber;
	if (Obj && (new Date().getDate() == JSON.parse(Obj).time)) {
        $(".browseNumber").text(JSON.parse(Obj).browseNumber);
	} else {
		browseNumber = Math.ceil(Math.random() * (300 - 50) + 50);
		let Obj = JSON.stringify({
			browseNumber,
			time: new Date().getDate()
		});
		localStorage.setItem("browseNumber", Obj);
		$(".browseNumber").text(browseNumber);
	}
};
